import Postil from '../components/ckextra/Postil';
import Revision from '../components/ckextra/Revision';
import editorUtil from './ckextraEditorUtil';

const functionNames = [
  'creatPostil','deletePostil','deleteAllPostil','showPostilList','findPreviousItem','findNextItem','refreshPostil','registerChoosePostil', 'doTrim', 'setShowRevision'
];

let util = {
  reviseWithDeletingText: editorUtil.reviseWithDeletingText,
  reactReady: () => {
    Revision.getCurrentStore() && Revision.getCurrentStore().init();
    Postil.getCurrentStore() && Postil.getCurrentStore().init();
  },
  revision: (show) => Revision.getCurrentStore() && Revision.getCurrentStore().toggleRevising(show),
  receiveReviseAndMoveToNext: () => Revision.getCurrentStore() && Revision.getCurrentStore().receive(true),
  receiveOneRevise: () => Revision.getCurrentStore() && Revision.getCurrentStore().receive(false),
  receiveAllRevise: () => Revision.getCurrentStore() && Revision.getCurrentStore().receiveAll(),
  rejectReviseAndMoveToNext: () => Revision.getCurrentStore() && Revision.getCurrentStore().reject(true),
  rejectOneRevise: () => Revision.getCurrentStore() && Revision.getCurrentStore().reject(false),
  rejectAllRevise: () => Revision.getCurrentStore() && Revision.getCurrentStore().rejectAll(),
  showReviseList: (flag) => Revision.getCurrentStore() && Revision.getCurrentStore().showReviseList(!flag),
  findPrevious: () => Revision.getCurrentStore() && Revision.getCurrentStore().findPrevious(),
  findNext: () => Revision.getCurrentStore() && Revision.getCurrentStore().findNext(),
  getRevisionData: () => Revision.getCurrentStore() && Revision.getCurrentStore().getRevisionData(),
  clearAvtiveRevisionParams: () => Revision.getCurrentStore() && Revision.getCurrentStore().clearAvtiveRevisionParams(),
  refreshChooseStatus: () => Revision.getCurrentStore() && Revision.getCurrentStore().refreshChooseStatus(),
};
functionNames.forEach((functionName) => {
  util[functionName] = (...args) => {
    const postilStore = Postil.getCurrentStore();
    if (postilStore) {
      postilStore[functionName](...args);
    }
  }
});

export default util;